
#ifndef   __STRING_LIB
#define   __STRING_LIB

#define   TYPE_BYTE			1
#define   TYPE_INTEGER		2
#define   TYPE_LONG			4

/* ERRORS */
extern int errno;
enum
{
	NO_ERR,
	NO_NUMBER 
};

extern const char *gpStr;

char *StrChr( char * ptr, char chr);
int StrnCmp(const char * s1, const char * s2, int len);
char* StrStr( char * s1,  char * s2);

int StrFindNumber ( const char* Str, int Number );
int StrCheckNumberRange ( const char* Str, int RangeMin, int RangeMax );
	
//unsigned char StrCmp ( const unsigned char *s1, const unsigned char *s2 );   
int StrCmp(register const char * s1, register const char * s2);
unsigned char* MemCpy ( unsigned char *m1, const unsigned char *m2, unsigned int ByteNumber );
char* StrCpy ( char *s1, const char *s2 );
void MemSet ( unsigned char *m, unsigned int ByteNumber, unsigned char FillByte );
//unsigned char MemCmp ( const unsigned char *s1, unsigned char *s2, unsigned char BytesNumber );
int MemCmp ( unsigned char* s1, unsigned char* s2, unsigned char BytesNumber );
long StrToLong( const char* s );
char* LongToStr( char* s, unsigned long Val );
char* ByteToStr_10( char* s, unsigned long Val  );
/* Lond with point. Example: Val=12 -> 0.12; Val = 309 -> 3.09; Val = 234789 -> 2347.89*/
char* Long_pToStr( char* s, unsigned long Val );

/* return length of string. If length > 512 return ERROR: ( -1) */
int StrLen( const char *s );

void Int_BCD_ToStr( unsigned char *s, unsigned int Integer );
unsigned int StrTo_Int_BCD( unsigned char *s );
char* StrCat( char* to, const char* from );
unsigned char* StrnCat(unsigned char* to, const unsigned char* from, unsigned char size);
unsigned long StrToBCD_Long( unsigned char* Str );
/* return index of first found NUMBER. Example: "ABCD 2345Sa" return: 5 */
int StrFindToken_Number ( unsigned char* Str );
unsigned char* BCD_ToStr( unsigned char* Str, unsigned long BCD );

/* return number of Str bytes (digit of BCD) */
//unsigned char StrToBCD_Long( unsigned char* Str_BCD, unsigned char* Str );

char* StrCat_UpTo_Ch(  char* to, const char* from, unsigned char Ch );

char* StrCpy_UpTo_Ch ( char *s1, const char *s2, char Ch );

int FindCharOffset ( unsigned char* Str, unsigned char Ch );

// /* return: offset of next Position after the Char; Number - Char by order */
// int FindCharNumber ( unsigned char* Str, unsigned char Ch, unsigned char Number );

/* return: pointer of next Position after the Char; Number - Char by order */
unsigned char* FindCharNumber ( unsigned char* Str, unsigned char Ch, unsigned char Number );

/* find the char and set end of line token ('0') on the char place */
int StrReplaceChar ( unsigned char* Str, unsigned char Ch, unsigned char Replace ) ;
/* return: how many characters was replaced */
int StrReplaceCharAll ( unsigned char* Str, unsigned char Ch, unsigned char Replace );

unsigned char* CharToHex( unsigned char* Hex, unsigned char* Char );

/* return amount of converted bytes; if - OK => CharnToHex() == ByteCount  */
int CharnToHex( unsigned char* Hex, char* Char, unsigned char ByteCount );

unsigned char* HexToChar( unsigned char* Char, unsigned char* Hex, unsigned char HexCount );

/* return amount of converted chars */
int StrToBCD ( unsigned char* Str_BCD, char* Str, unsigned char Str_BCD_Len );
unsigned char* BCDToStr( unsigned char* Char, unsigned char* BCD, unsigned char BCDCount );
extern int PREFIX_EDIT;

void FlipFlopN ( unsigned char* Str, unsigned char Len );
void FlipFlop  ( unsigned char* Str );

/* Check if each element == Ch */
unsigned char Str_If_All_Set( unsigned char* Str, unsigned char Ch );

/* return pointer on 'Ch' by order; 
example p = FindCharByOrder(MyStr, ','  3) Str[]="Data: 1, 33, 567, 009" 
Will be returned pointer on third ',' characters (the comma after 567)*/
unsigned char* FindCharByOrder ( unsigned char* Str, unsigned char Ch, unsigned char ChNum );

// return pointer of first char after Number;
// Example: p = StrPullOutNumber(MyNumber, "Frequency: 2400MHz, 8100, 8675");  
// Result: return pointer (p) on 'M'char
unsigned char* StrPullOutNumber ( unsigned char* Number, unsigned char* Str );

// return amount of the Char into Str;
int StrCountChar ( unsigned char* Str, unsigned char Char );
void StrInsert( unsigned char* To, unsigned char* What  );

/* Copy the contents between two Char from Source to Destination; return pointer at the character after Char; 
example: 
 Source: +CMGL: 3,"REC READ","616",,"08/03/06,15:15:16+00"
If the Char is '"' in Distination will be REC READ; return pointer at the second coma (,); */
unsigned char* StrCutBetweenChars( unsigned char* Destination, unsigned char* Source, unsigned char Char );

#define   ClearBuffer(b,ByteNumber) 	MemSet(b, ByteNumber, 0)	

#endif

